package com.cindata

import com.cindata.dictionary.AssessTypeDict
import com.cindata.dictionary.AssessStatusDict

class Assess
{

    Long communityId
    Account account

    City city
    String address
    String communityName
    String building
    String unit
    String house

    Integer floor
    Integer totalFloor
    Integer buildYear

    Double area
    Double finalPrice = 0
    // 成交总价
    Double externalAssessPrice = 0
    // 外部评估总价

    Double assessUnitPrice = 0
    Double assessTotalPrice = 0

    User user

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    Date evaluateDate
    String evaluateCode

    AssessTypeDict assessType
    // 1: 快速评估  2：人工评估

    AssessStatusDict assessStatus
    // 1: 评估成功  2: 评估中  -1: 评估失败

    String failReason

    Boolean isFrequency = false

    static mapping = {
        autowire true
    }

    static constraints = {

        communityId nullable: true, blank: true

        city nullable: true, blank: true
        address maxSize: 150, nullable: true, blank: true
        communityName maxSize: 50, nullable: true, blank: true
        building maxSize: 50, nullable: true, blank: true
        unit maxSize: 50, nullable: true, blank: true
        house maxSize: 50, nullable: true, blank: true
        floor nullable: true, blank: true
        totalFloor nullable: true, blank: true
        buildYear nullable: true, blank: true
        area nullable: true, blank: true
        finalPrice nullable: true, blank: true
        externalAssessPrice nullable: true, blank: true

        assessUnitPrice nullable: true, blank: true
        assessTotalPrice nullable: true, blank: true

        user nullable: true, blank: true

        assessType nullable: true, blank: true
        assessStatus nullable: true, blank: true

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true

        isFrequency nullable: true, blank: true

        evaluateDate nullable: true, blank: true
        evaluateCode maxSize: 50, nullable: true, blank: true

        failReason maxSize: 200, nullable: true, blank: true

        account nullable: true, blank: true
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        user = User.findByUsername(username)
        if (!account)
        {
             account = user?.account
         }

    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
    }
}
